package br.ufpe.cin.analysis.plugin.charts;

import java.io.IOException;

import javax.xml.bind.JAXBException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.plot.PlotOrientation;

import br.ufpe.cin.analysis.plugin.models.BarDataset;
import br.ufpe.cin.analysis.plugin.entities.Process;

public class BarChart extends Chart<BarDataset> {

	private PlotOrientation orientation;
	private String axisA,axisB;


	public BarChart(BarDataset dataset, PlotOrientation orientation, String axisA, String axisB){

		this.orientation = orientation;
		this.axisA = axisA;
		this.axisB = axisB;

		this.setDataset(dataset);


	}

	public BarChart(String xmlFileName, PlotOrientation orientation, String axisA, String axisB) throws JAXBException, IOException{

		this.orientation = orientation;
		this.axisA = axisA;
		this.axisB = axisB;

		this.setDataset( new BarDataset(xmlFileName) );


	}

	public BarChart(Process process, PlotOrientation orientation, String axisA, String axisB){

		this.orientation = orientation;
		this.axisA = axisA;
		this.axisB = axisB;

		this.setDataset(new BarDataset(process));


	}

	@Override
	public void init() {
		
		this.setJChart( ChartFactory.createBarChart(this.getDataset().getProcess().getName(),this.axisA , this.axisB, this.getDataset().getJFreeChartDataset(), this.orientation, true, true, true));

	}

	public PlotOrientation getOrientation() {
		return orientation;
	}

	public void setOrientation(PlotOrientation orientation) {
		this.orientation = orientation;
		this.getJChart().getCategoryPlot().setOrientation(this.orientation);
	}

	public String getAxisA() {
		return axisA;
	}

	public void setAxisA(String axisA) {
		this.axisA = axisA;
		this.getJChart().getCategoryPlot().getDomainAxis().setLabel(this.axisA);
	}

	public String getAxisB() {
		return axisB;
	}

	public void setAxisB(String axisB) {
		this.axisB = axisB;
		this.getJChart().getCategoryPlot().getRangeAxis().setLabel(this.axisB);
	}
	
	

}
